<!DOCTYPE html>
<html>
  <head>
    <title>Testing navigation tracking</title>
    <meta charset="utf8"/>
    <meta name="referrer" content="origin">
  </head>
  <body>
    <iframe id="inner"/></iframe>
    <script src="./post_data.js"></script>
    <script type="module">
     import { runAllTests } from "./test_utils.js"
     import { tests } from "./test_definitions.js";

     const searchParams = new URLSearchParams(window.location.search);
     const thirdparty = searchParams.get("thirdparty");
     const mode = searchParams.get("mode");
     const iframe_root = (location.hostname === "localhost" ||
                          location.hostname === "127.0.0.1" ||
                          location.hostname === "")
                       ? "" : "https://test-pages.privacytests2.org";
     const listener = async (event) => {
       if (!event.origin.includes("privacytests")) {
         return;
       }
       const data = JSON.parse(event.data);
       if (data.command === "disableDarkMode" || data.command === "enableDarkMode") {
         return;
       }
       removeEventListener("message", listener);
       const topLevelResults = await runAllTests(await tests(), { category: "navigation_toplevel" });
       const allData = {...data, ...topLevelResults};
       document.body.setAttribute("data-test-results", JSON.stringify(allData));
       await postDataAndCarryOn(allData, `navigation_${mode}_${thirdparty}`);
     };
     addEventListener("message", listener);
     const iframe = document.getElementById("inner");
     iframe.src = `${iframe_root}/navigation_inner.html${window.location.search}`;
    </script>
  </body>
</html>
